import { h, Component } from 'vue'
import { NIcon, NTag } from 'naive-ui'
import moment from 'moment'

export const renderIcon = (icon: Component) => {
    return () => h(NIcon, null, { default: () => h(icon) })
}

export type NTagType = 'default' | 'error' | 'primary' | 'info' | 'success' | 'warning' | undefined
export const renderTag = (name: string, type: NTagType = 'info') => {
    return h(NTag, { type: type, size: 'small' }, { default: () => name })
}

export const defaultTimeFormatter = 'yyyy-MM-DD hh:mm:ss'
export const formatTime = (time: string) => {
    return moment(time).format(defaultTimeFormatter)
}